import {createStore} from 'redux';
//导入封装的方法
import mutations from './actions'
// 定义state数据
let defaultState = {count:0,back:false,title:'首页',selectBarIndex:0,isTabBarShow:true,isSearchShow:true};
//定义redux函数,该变量是一个函数,该函数用来定义具体state数据源的更改操作
const reducer = function(state = defaultState,action){
    // 判断是否需要外部参数干预state值
    let newState = null
    if(action.hasOwnProperty('params')){
        //action.type 是mutations对象的键名。
        newState = mutations[action.type] ? mutations[action.type](state,action.params) : state;
    }else{
        //如果params为空说明外界更改数据不需要依托外部传递的数据
        newState = mutations[action.type] ? mutations[action.type](state) : state;
    }
    return {...state,...newState}
}
let store = createStore(reducer);
export default store